# BASE VIEW
# -----------------------------------------------------------------------------
# This serves as the base for all app views.

class BaseView

    id: null
    dom: {}

    # Set the DOM elements.
    setDom: (arr) =>
        @addDomElement selector for selector in arr

    # Add a reference to an element based on the selector.
    # First character selectors (dot and hash) will be replaced.
    addDomElement: (selector) =>
        firstChar = selector.substring 0, 1
        domId = selector.substring(1) if firstChar is "#" or firstChar is "."
        domId = domId.replace RegExp(" ", "g"), ""
        domId = domId.replace RegExp(">", "g"), "_"
        @dom[domId] = $ selector


    # VISUAL ALERTS
    # -------------------------------------------------------------------------

    # Display an alert with a title and message to the user.
    showAlert: (title, message) =>
        alert message


    # HELPER METHODS
    # -------------------------------------------------------------------------

    # Warn the user about an empty or invalid field, by blinking with a red background.
    warnField: (field) =>
        field.addClass "warn"
        callback = () -> field.removeClass "warn"
        setTimeout callback, App.Settings.UI.fieldWarnDelay


# APPEND VIEW TO WINDOW
# -----------------------------------------------------------------------------
window.App.BaseView = BaseView